﻿using System;
using System.Data;
using System.Data.OracleClient;


namespace ik.DB.Oracle
{
    public class clDbORA : clDB
    {
        #region "ToString"
        /// <summary>
        /// class information
        /// </summary>
        /// <returns>String</returns>
        public override String ToString()
        {
            return "Class name: ik.DB.Oracle \n\n" +
                   "Class version: " + Environment.Version.ToString() + "\n" +
                   "OS version: " + Environment.OSVersion.ToString() + "\n" +
                   "Computer name: " + Environment.MachineName + "\n" +
                   "Rights: (c) 2011 - by Ivan Kruger";
        }
        #endregion

        /// <summary>
        /// contrutor
        /// </summary>
        public clDbORA() : base(enSGBD.Oracle)
        {
        }

        #region "GetCnn"
        /// <summary>
        /// conecta a uma base oracle
        /// </summary>
        /// <param name="user">nome do usuario</param>
        /// <param name="pwd">senha encriptada</param>
        /// <param name="dataSource">local do banco de dados (IP/DNS)</param>
        /// <param name="lifeTime">connection time out</param>
        public void GetCnn(String user, String pwd, String dataSource, Int32 lifeTime)
        {
            try
            {
                cnnString = String.Format("Password={0};User ID={1};Data Source={2};Connection LifeTime={3};",
                            ik.FunctionsDB.clFunctionsDB.CrypTo2(pwd, FunctionsDB.enEncryption.Descriptar),
                            user,
                            dataSource,
                            lifeTime.ToString());


                if (cnnDB == null)
                    cnnDB = new OracleConnection(cnnString);
                if (cnnDB.State != ConnectionState.Open)
                    cnnDB.Open();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }

}

